package com.company.aop.annotationdev;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.stereotype.Component;

/**
 * @ClassName MyAspect
 * @Description 切面类
 */
@Component("myAspect")
@Aspect // 告知Spring，当前类是一个切面类
@EnableAspectJAutoProxy(proxyTargetClass = true)
public class MyAspect {

    @Before(value = "execution(* com.company.service.*.*.*(..)))")
    public void before(){
        System.out.println("前置增强方法······");
    }

    /**
     * @param proceedingJoinPoint 连接点（切点）
     */
    @Around(value = "execution(* com.company.service.*.*.*(..)))")
    public void around(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
        System.out.println("<---······环绕前增强方法······--->");
        // 目标方法
        proceedingJoinPoint.proceed();
        System.out.println("<---······环绕后增强方法······--->");
    }

    @AfterReturning(value = "execution(* com.company.service.*.*.*(..)))")
    public void afterReturn(){
        System.out.println("后置增强方法 ······");
    }

    @After(value = "execution(* com.company.service.*.*.*(..)))")
    public void after(){
        System.out.println(" ~ ~ ~ 最终增强方法 ~ ~ ~");
    }

    @AfterThrowing(value = "execution(* com.company.service.*.*.*(..)))")
    public void afterThrowing(){
        System.out.println("afterThrowing ··· 异常 ··· ");
    }

}
